package com.yq.cp.controller.permission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yq.cp.entity.permission.dto.UserDto;
import com.yq.cp.service.permission.UserService;
import com.yq.cp.config.UserThreadLocal;
import com.yq.cp.entity.permission.vo.UserVo;
import com.yq.cp.entity.common.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zh
 * @since 2022-09-21
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("add")
    public ApiResult add(@RequestBody UserVo vo){
        vo.setCreateUserId(UserThreadLocal.get().getId());
        userService.add(vo);
        return ApiResult.ok();
    }

    @PostMapping("update")
    public ApiResult update(@RequestBody UserVo vo){
        vo.setCreateUserId(UserThreadLocal.get().getId());

        userService.update(vo);
        return ApiResult.ok();
    }
    @PostMapping("updateState")
    public ApiResult updateState(@RequestBody UserVo vo){
        userService.updateState(vo);
        return ApiResult.ok();
    }

    @PostMapping("delete")
    public ApiResult delete(@RequestBody UserVo vo) {
        vo.setCreateUserId(UserThreadLocal.get().getId());
        userService.delete(vo);
        return ApiResult.ok();

    }
    @PostMapping("page")
    public ApiResult page(@RequestBody UserVo vo){

        List<Integer> list=new ArrayList<>();
        list.add(10);
        list.add(11);
        list.add(20);
        list.add(21);
        list.add(22);
        vo.setTypes(list);
        IPage<UserDto> page = userService.page(vo);
        return ApiResult.ok().data(page);
    }

}

